package ch.mtb.conwin;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JComponent;

/**
 * A 2D grid square on which the players can move
 */

public abstract class World extends JComponent {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private int dimensions;
    protected int squareWidth;

    /**
     * Creates a grid with default dimensions and a default number of players
     */
    public World() {
        // * super();
        dimensions = 30;
        squareWidth = 15;//7;
        // if (ConWin.verbose) System.out.println("Player created");

    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        for (int y = 0; y < dimensions; y++)
            for (int x = 0; x < dimensions; x++) {
                g.setColor(Color.black);
                g.fillRect(squareWidth * x, squareWidth * y, squareWidth,
                        squareWidth);
                // g.setColor(Color.black);
                // g.drawRect(squareWidth*x,squareWidth*y,squareWidth,squareWidth);
            }
    }

    public Dimension getPreferredSize() {
        return new Dimension(dimensions * squareWidth, dimensions * squareWidth);
    }

    /**
     * Sets the Dimensions of the grid
     */
    public void setDimensions(int xYMax) {
        dimensions = xYMax;
    }

    /**
     * Returns the Dimensions of the grid
     */
    public int getDimensions() {
        return dimensions;
    }

    // check if the coordinates are beyond the world boundaries and if so,
    // put position back according to boundarGuard rule
    public abstract int boundaryGuard(int position);

}